<?php 
  class OrderController extends CommonController{
  private $model;

  public function __init(){
       
     // 为了不覆盖父类里面的init方法
    	parent::__init();
    	$this->model=K('Order');
    	 if(!isset($_SESSION['uid']) || !isset($_SESSION['username'])){
     
      $this->success('您还没有登录，请先登录',U('User/login'),0);


}
}
      public function index(){
   
    // 获取选中的购物车列表数据

     $sid=Q('post.sid');
     $number=Q('post.number');
      $money=0;
     foreach ($sid as $k => $v) {
        //修改购物车商品数量
        $update=array(
          'sid'=>$v,
          'num'=>$number[$k],
        );
        Cart::update($update);

        $data[$k]=$_SESSION['cart']['goods'][$v];
   
       
        $money+=$data[$k]['total'];
        $data[$k]['sid']=$v;
      }
    
  
  $this->assign('data',$data);
  $this->assign('money',$money);

  // p($data);p($money);


       $this->display();


      }


public function success_order(){
   $uid=$_SESSION['uid'];
    $data=K('Order')->where("uid={$uid}")->order('time desc')->find();
    // $total=cart::getTotalPrice(); //总计
    // $number=Cart::getOrderId();
   // $this->assign('number',$number);
   //   $this->assign('total',$total);
    // p($data);
     $this->assign('data',$data);

   $this->display();
   

}

public function add(){
  // 提交订单
 if(IS_POST){
 // p($_POST);die;
if(!$this->model->addData()){
  	$this->error($this->model->error);
  }

// p($data);die;
   unset($_SESSION['cart']);
   go(U('success_order'));

	
 	}
 
 }








  }





 ?>